Skip to content

Update NanoVDB for single-space GridHandle and widen Torch-pool coverage - #752

Open
swahtz wants to merge 1 commit into
openvdb:mainfrom
swahtz:feat/nanovdb-single-space-adoption
Open

Update NanoVDB for single-space GridHandle and widen Torch-pool coverage#752
swahtz wants to merge 1 commit into
openvdb:mainfrom
swahtz:feat/nanovdb-single-space-adoption

Conversation

@swahtz

@swahtz swahtz commented Aug 23, 2026

Copy link
Copy Markdown
Contributor

What this PR does

Follow-up to #732. Upstream has since merged openvdb #2286 (small-builder ResourceT seams — already in our previous pin, and our only relevant call site, indexToGrid in SaveNanoVDB.cu, was already routed) and #2288 (single-space device-only GridHandle<cuda::Buffer<T,R>>, step 3 part 1 of openvdb #2232). This PR advances the pin past #2288 and widens Torch-allocator coverage where it is reachable today.

1. Pin bump: 7946f17ee679862f

The merge commit of upstream #2288. The new hasDeviceSingle/hasHostSingle traits are detected, defaulting to false, so TorchDeviceBuffer's dual-trait specialization compiles and behaves unchanged.

2. ReinitializeSdf: VBM metadata buffers through the Torch pool

The VoxelBlockManager's firstLeafID/jumpMap buffers were allocated with nanovdb::cuda::DeviceBuffer — outside torch's pool (and, with NANOVDB_USE_SYNC_CUDA_MALLOC builds, via synchronous cudaMalloc). They now allocate through BuilderResource via a local TorchVbmBuffer adapter over the single-space nanovdb::cuda::Buffer, stream-ordered on the reinit stream.

Why an adapter and not cuda::Buffer directly: VoxelBlockManagerHandle's device accessors are gated on BufferTraits<BufferT>::hasDeviceDual and static_cast their pointers from a void*-returning deviceData(), and buildVoxelBlockManager allocates through the legacy BufferT::create(bytes, guide, device, stream) static interface. Bringing the VBM handle into the single-space world is an upstream follow-up on the #2232 roadmap (noted in the adapter's doc comment).

3. SaveNanoVDB: device staging onto cuda::Buffer<…, BuilderResource>

The defensive host-grid upload buffer and the per-batch (N+1)-element value staging buffer become nanovdb::cuda::Buffer over BuilderResource, stream-ordered on the save stream (previously TorchDeviceBuffer via stream-less raw_alloc). The indexToGrid output handle stays TorchDeviceBuffer: upstream's builder output path (getBufferBufferT::createdeviceData()) still requires a dual-trait buffer; #2288's edits to IndexToGrid.cuh/AddBlindData.cuh were grid-index hardening, not single-space output support.

4. TorchDeviceBuffer: stream-correct allocation

The constructor gains an optional stream and uses raw_alloc_with_stream; create() forwards the stream nanovdb builders pass instead of discarding it (the same fix review flagged on the old #655 fork). Previously the allocation was silently associated with the device's current torch stream, which is only correct when that coincides with the builder's stream. Null stream keeps the previous behavior, so all existing two-argument constructor call sites are unchanged.

What is deliberately NOT here

Replacing TorchDeviceBuffer with GridHandle<cuda::Buffer<uint8_t, TorchResource>> for grid storage stays blocked on upstream step-3 parts 2–3: cross-space transfers are a named compile error until part 2, and the pinned-host create mapping lands in part 3 — both required for GridBatch's CPU grids and .to(device).

Testing

  • Full rebuild of _fvdb_cpp (112 targets, sm_120) with zero warnings under -Werror=all-warnings / -Wall -Werror.
  • tests/unit/test_sdf.py 10/10 (exercises the VBM adapter), tests/unit/test_io.py 622/622 (exercises the SaveNanoVDB staging path), tests/unit/test_basic_ops.py 276 passed / 1 skipped (carries the torch peak-memory bounds sensitive to allocator routing) — on an RTX PRO 6000 Blackwell, PyTorch 2.13.

🤖 Generated with Claude Code

@swahtz
swahtz requested a review from a team as a code owner August 23, 2026 23:14
@swahtz
swahtz requested review from matthewdcong and sifakis August 23, 2026 23:14
@swahtz swahtz changed the title Advance NanoVDB pin past single-space GridHandle and widen Torch-pool coverage Update NanoVDB for single-space GridHandle and widen Torch-pool coverage Aug 23, 2026
… coverage

Bump the NanoVDB pin from 7946f17e to e679862f, the merge commit of
openvdb #2288 (single-space device GridHandle<cuda::Buffer<T,R>>). The
new hasDeviceSingle/hasHostSingle buffer traits are detected with false
defaults, so TorchDeviceBuffer's dual-trait specialization is unaffected.

On top of the bump, three allocator-coverage improvements:

- ReinitializeSdf: the VoxelBlockManager's firstLeafID/jumpMap buffers
  now allocate through BuilderResource (torch's active CUDA allocator)
  via a local TorchVbmBuffer adapter, instead of DeviceBuffer's separate
  pool. The upstream VBM handle still requires the legacy dual-buffer
  static interface (hasDeviceDual gates + BufferT::create + a
  void*-returning deviceData()), so the single-space cuda::Buffer is
  wrapped rather than used directly; the adapter documents the upstream
  follow-up (openvdb #2232).

- SaveNanoVDB: the device staging buffers (the defensive host-grid
  upload and the per-batch (N+1)-element value buffer) become
  nanovdb::cuda::Buffer over BuilderResource, stream-ordered on the save
  stream. The indexToGrid output handle stays TorchDeviceBuffer: the
  builder's output path still requires a dual-trait buffer upstream.

- TorchDeviceBuffer: CUDA allocations can now be associated with an
  explicit stream (raw_alloc_with_stream), and create() forwards the
  stream nanovdb builders pass instead of discarding it. Previously the
  allocation was silently associated with the device's current torch
  stream, which is only correct when that coincides with the builder's
  stream.

Verified: full rebuild (112 targets, sm_120, -Werror=all-warnings clean);
tests/unit/test_sdf.py 10/10, test_io.py 622/622, test_basic_ops.py
276/276 (+1 skip) on an RTX PRO 6000 Blackwell.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Signed-off-by: Jonathan Swartz <jonathan@jswartz.info>
@swahtz
swahtz force-pushed the feat/nanovdb-single-space-adoption branch from 268ea68 to 2d0eb61 Compare August 23, 2026 23:23
@harrism

harrism commented Aug 27, 2026

Copy link
Copy Markdown
Contributor

Can this be updated based on the recently merged step 3 PRs (2292, 2293), and the now open 3-3 #2301?

@swahtz

swahtz commented Aug 27, 2026

Copy link
Copy Markdown
Contributor Author

Can this be updated based on the recently merged step 3 PRs (2292, 2293), and the now open 3-3 #2301?

Indeed. I was putting this together from the last tranche of PRs but then saw the other ones were moving quickly so thought I'd hold off for the opportunity to cover those other ones.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants